<template>
  <div>
      <el-table
    :data="cateList"
    style="width: 100%;margin-bottom: 20px;"
    row-key="id"
    border
    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="catename" label="分类名称"></el-table-column>
      <el-table-column label="图片">
        <template v-slot="scoped">
          <div>
            <img :src="$pre + scoped.row.img" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="primise" v-if="scoped.row.status==1" >启 动</el-button>
            <el-button type="primise"  v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column  label="操作">
        <template v-slot="scoped">
          <div>
            <el-button type="primise" @click="edit(scoped.row.id)">编 辑</el-button>
            <el-button type="primise" @click="del(scoped.row.id)">删 除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {cateDel} from "../../../request/api.js"
import { sucessAlert, warningAlert } from '../../../utils/alert.js';
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      cateList: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      CateAsyncList: "cate/acyncChangeList",
    }),
    edit(id) {
        this.$emit("edit",id)
    },
    del(id){
        cateDel({id:id}).then(res=>{
            if(res.data.code==200){
                sucessAlert(res.data.msg);
                 this.CateAsyncList();
            }else{
                warningAlert(res.data.msg)
            }
        })
    }
  },
  mounted() {
    this.CateAsyncList();
  },
};
</script>
<style scoped>
img {
  width: 150px;
  height: 150px;
}
</style>